<template>
	<app-layout>
		<app-banner></app-banner>
		<view class="entity-page">
			<app-title text="推荐实物" :width="64"></app-title>
			<view class="find-box">
				<view class="box-item" v-for="item in listData" :key="item.id">
					<image class="prod-img" :src="item.subPctureUrl" mode=""></image>
					<view class="prod-info">
						<text class="prod-name">{{item.title}}</text>
						<text class="prod-other">￥ {{item.price}}</text>
					</view>
					<button class="prod-bay" type="default">
						<view class="prod-bay-content" @click="goToProdDetail(item.id)">
							<text>立即购买</text>
							<view class="bay-right"></view>
						</view>
					</button>
				</view>
			</view>
			<uni-load-more :contentText="contentText" @clickLoadMore="onClickLoadMore" :status="queryStatus">
			</uni-load-more>
		</view>
	</app-layout>
</template>

<script>
	import {
		getCommodityPage
	} from '../../request/entity-api.js'
	export default {
		data() {
			return {
				// 主题数组
				listData: [],
				// 列表查询参数
				params: {
					condition: "",
					pageNum: 0,
					pageSize: 10
				},
				// 没有更多了
				isNoMore: false,
				// 加载状态
				queryStatus: 'more',
				// 各状态文字说明
				contentText: {
					contentdown: "点击加载更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了"
				}
			}
		},
		created() {
			this.onLoadListData()
		},
		methods: {
			// 跳转详情
			goToProdDetail(id) {
				uni.navigateTo({
					url: `../blindBox-detail/blindBox-detail?id=${id}`,
					animationType: 'pop-in',
					animationDuration: 200
				})
			},
			// 点击加载更多
			onClickLoadMore() {
				if (!this.isNoMore) {
					this.onLoadListData()
				}
			},
			// 加载 数据
			async onLoadListData() {
				this.queryStatus = 'loading'
				this.params.pageNum += 1
				try {
					let {
						code,
						message,
						data
					} = await getCommodityPage(this.params)
					if (code === 200) {
						if (this.params.pageNum <= (data.totalPage || 1)) {
							this.isNoMore = false
							this.listData.push(...data.list)
							this.queryStatus = 'more'
						} else {
							this.isNoMore = true
							this.queryStatus = 'noMore'
						}
					} else {
						this.queryStatus = 'more'
						uni.showToast({
							title: message,
							icon: 'error'
						})
					}
				} catch {
					this.queryStatus = 'more'
					uni.showToast({
						title: '服务繁忙',
						icon: 'error'
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.entity-page {
		width: 100%;
	}

	.find-box {
		margin: 20rpx 0;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;

		.box-item {
			width: 50%;
			height: 570rpx;
			margin-bottom: 40rpx;
			background: $common-prod-back-url no-repeat;
			background-size: 364rpx 570rpx;
			background-position: center center;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			position: relative;

			.prod-img {
				width: 268rpx;
				height: 294rpx;
			}


			.prod-info {
				margin-top: 30rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.prod-name {
					font-size: 28rpx;
					font-family: SourceHanSansCN-Bold, SourceHanSansCN;
					font-weight: bold;
					color: #BFCBCD;
					line-height: 48rpx;
				}

				.prod-other {
					font-size: 12px;
					font-family: SourceHanSansCN-Regular, SourceHanSansCN;
					font-weight: 400;
					color: #BFCBCD;
					line-height: 18px;
				}
			}

			.prod-bay {
				width: 350rpx;
				height: 196rpx;
				font-size: 14px;
				font-family: SourceHanSansCN-Regular, SourceHanSansCN;
				font-weight: 400;
				color: #FFBD47;
				position: absolute;
				bottom: -70rpx;
				background: $common-bay-url no-repeat;
				background-size: 350rpx 200rpx;
				background-position: center center;
				display: flex;
				align-items: center;
				justify-content: center;

				.prod-bay-content {
					width: 240rpx;
					height: 80rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					z-index: 2;
				}

				.bay-right {
					width: 40rpx;
					height: 40rpx;
					background: $common-right-url no-repeat;
					background-size: 100% 100%;
					background-position: center center;
				}
			}

			.prod-bay:after {
				border: none;
			}

		}
	}
</style>
